package io.renren.modules.generator.controller;

import java.util.List;
import java.util.Map;

import io.renren.modules.generator.dto.DynamicDto;
import io.renren.modules.generator.vo.DynamicVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.generator.entity.DynamicEntity;
import io.renren.modules.generator.service.DynamicService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 *
 *
 * @author jianzhen
 * @email sunlightcs@gmail.com
 * @date 2022-05-04 15:12:38
 */
@RestController
@RequestMapping("generator/dynamic")
public class DynamicController {
    @Autowired
    private DynamicService dynamicService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = dynamicService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 查看我的动态
     */
    @RequestMapping("/info")
    public R info(){
		List<DynamicVo> dynamicEntities = dynamicService.getMyDynamic();

        return R.ok().put("dynamic", dynamicEntities);
    }

    /**
     * 查看社区动态
     */
    @RequestMapping("/allInfo")
    public R allInfo(){
        List<DynamicVo> dynamicEntities = dynamicService.getAllInfo();

        return R.ok().put("dynamic", dynamicEntities);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody DynamicDto dynamic){
		dynamicService.saveDynamic(dynamic);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody DynamicEntity dynamic){
		dynamicService.updateById(dynamic);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete/{id}")
    public R delete(@PathVariable("id") Integer dynamicId){
		dynamicService.removeDynamic(dynamicId);

        return R.ok();
    }

    @RequestMapping("/like/{id}")
    public R like(@PathVariable("id") Integer dynamicId){
        dynamicService.like(dynamicId);

        return R.ok();
    }

    @RequestMapping("/cancelLike/{id}")
    public R cancelLike(@PathVariable("id") Integer dynamicId){
        dynamicService.cancelLike(dynamicId);

        return R.ok();
    }

}
